<template>
    <router-view />
    <van-tabbar route>
      <van-tabbar-item to="/" icon="home-o">首页</van-tabbar-item>
      <van-tabbar-item to="/class" icon="wap-nav">分类</van-tabbar-item>
      <van-tabbar-item to="/car" icon="cart-o">购物车</van-tabbar-item>
      <van-tabbar-item to="/login" icon="manager-o" v-if="!token"
        >登录</van-tabbar-item
      >
      <van-tabbar-item to="/user" icon="manager-o" v-else>我的</van-tabbar-item>
    </van-tabbar>
  </template>
  
  <script setup lang="ts">
  import { ref, onMounted } from "vue";
  import type { Ref } from "vue";
  import { useUserInfoStore } from "@/stores/userInfo";

  const token: Ref<string> = ref("");
  const store = useUserInfoStore();
  
  onMounted(() => {
    if (!token.value && localStorage.getItem("userToken")) {
      store.userToken = localStorage.getItem("userToken") as string;
      token.value = store.getUserToken;
    }
  });
  </script>
  
  <style></style>
  